<template>
  <div class="memories-contain">
    <van-nav-bar title="近期日子">
      <template #left>
        <span @click="$router.back()">
        <svg-icon style="margin-left: 10px;" icon-class='fanhui' width="30px" height="30px" class="icon"/>
        </span>
      </template>
    </van-nav-bar>
    <div class="box">
      <div class="bline ltop"></div>
      <div class="bline lbottom"></div>
      <div class="bline lleft"></div>
      <div class="bline lright"></div>
      <div class="lhour" :style="{transform:`rotate(${hdeg}deg)`}"></div>
      <div class="lminute" :style="{transform:`rotate(${mdeg}deg)`}"></div>
      <div class="lsecond" :style="{transform:`rotate(${sdeg}deg)`}"></div>
    </div>
    <div class="time">{{ formatTime }}</div>
    <div class="date">{{ weekday }}<span class="circle">{{ nowday }}</span></div>
    <div class="drift" @click="$router.push({ path: '/calender' })">
      <svg-icon icon-class='xianxingyumaobi' width="30px" height="30px" class="icon"/>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'

export default {
  name: 'memoriesIndex',
  data () {
    return {
      hdeg: 0,
      mdeg: 0,
      sdeg: 0,
      timer: null,
      formatTime: dayjs().format('h:mm A'),
      weekday: `${dayjs().format('dddd')},${this.convertToChineseNumber(dayjs().month() + 1)}月`,
      nowday: dayjs().format('D')
    }
  },
  mounted () {
    this.timer = setInterval(() => {
      const day = new Date()
      this.hdeg = day.getHours() * 30 + day.getMinutes() * 0.5
      this.mdeg = day.getMinutes() * 6 + day.getSeconds() * 0.1
      this.sdeg = day.getSeconds() * 6 + day.getMilliseconds() * 0.006
    }, 1000)
  },
  beforeDestroy () {
    clearInterval(this.timer)
    this.timer = null
  },
  methods: {
    convertToChineseNumber (num) {
      const chineseNumbers = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
      return chineseNumbers[num]
    }
  }
}
</script>

<style scoped lang="less">
.memories-contain {
  background-color: #fff;
  height: 100vh;

  .van-nav-bar {
    &::after {
      border: none;
    }
  }

  .box {
    width: 180px;
    height: 180px;
    margin: 35px auto 25px;
    border-radius: 50%;
    position: relative;
  }

  .time {
    justify-content: center;
    font-size: 40px;
    display: flex;
  }

  .date {
    text-align: center;
    color: #aaa;
    font-size: 14px;
    letter-spacing: 0.3px;
    text-transform: uppercase;

    .circle {
      background-color: black;
      color: #fff;
      border-radius: 50%;
      height: 16px;
      width: 16px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      line-height: 15px;
      font-size: 10px;
      margin-left: 3px;
    }
  }

  .bline {
    width: 3px;
    height: 10px;
    background-color: black;
    position: absolute;
  }

  .ltop {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
  }

  .lbottom {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
  }

  .lleft {
    top: 50%;
    left: 5px;
    transform: translateY(-50%) rotate(90deg);
  }

  .lright {
    top: 50%;
    right: 5px;
    transform: translateY(-50%) rotate(90deg);
  }

  .lhour {
    width: 3px;
    height: 40px;
    background-color: #f1a760;
    position: absolute;
    left: 49%;
    top: 28%;
    transform-origin: bottom center;
  }

  .lminute {
    width: 3px;
    height: 50px;
    background-color: #e77052;
    position: absolute;
    left: 49%;
    top: 22%;
    transform-origin: bottom center;
  }

  .lsecond {
    width: 2px;
    height: 60px;
    background-color: #299d8b;
    position: absolute;
    left: 49%;
    top: 16%;
    transform-origin: bottom center;

    &:before {
      content: '';
      background: url("@/assets/rose.png") no-repeat;
      background-size: 15px 15px;
      width: 15px;
      height: 15px;
      position: absolute;
      top: -15px;
      left: -7px;
    }
  }

  .drift {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 45px;
    height: 45px;
    background-color: #f1a760;
    border-radius: 50%;
    position: fixed;
    bottom: 13%;
    right: 10%;
    box-shadow: 3px 2px 2px #ccc;
    z-index: 100;
  }
}

</style>
